package com.waiter.moximoxi.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.waiter.moximoxi.R;
import com.waiter.moximoxi.bean.OrderInfoBean;


import java.util.ArrayList;
import java.util.List;

import cn.yhong.aframework.adapter.ZmAdapter;
import cn.yhong.aframework.adapter.ZmHolder;
import cn.yhong.aframework.dialog.BaseDialog;

/**
 * Created by 17639 on 2020/10/15.
 */

public class SettlementOrderDialog extends BaseDialog implements View.OnClickListener {

    private ImageView dialog_sending_dis;
    private ListView sending_listview;
    private TextView total_count_tv;
    private TextView total_price_tv;

    private List<OrderInfoBean.OrderListBean> orderListBeans;
    private SettlementOrderAdapter settlementOrderAdapter;

    public SettlementOrderDialog(Context context) {
        super(context);
    }

    @Override
    public Dialog initDialog(Context context) {
        View view = View.inflate(context, R.layout.dialog_settlement_order, null);
        dialog_sending_dis = view.findViewById(R.id.dialog_sending_dis);
        sending_listview = view.findViewById(R.id.sending_listview);
        total_count_tv = view.findViewById(R.id.total_count_tv);
        total_price_tv = view.findViewById(R.id.total_price_tv);

        dialog_sending_dis.setOnClickListener(this);

        orderListBeans = new ArrayList<>();
        settlementOrderAdapter = new SettlementOrderAdapter(context, orderListBeans);
        sending_listview.setAdapter(settlementOrderAdapter);

        return initMatchWrapDialog(view, context, Gravity.CENTER, android.R.style.Animation_InputMethod);
    }

    public void showSettlementDialog(OrderInfoBean orderListBean) {
        try {
            orderListBeans.clear();
            orderListBeans.addAll(orderListBean.order_list);

            settlementOrderAdapter.notifyDataSetChanged();

            total_count_tv.setText("总量：" + orderListBean.order_list_count);
            total_price_tv.setText("总价：" + orderListBean.order_list_newprice);

            showDialog();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    class SettlementOrderAdapter extends ZmAdapter<OrderInfoBean.OrderListBean> {

        public SettlementOrderAdapter(Context mContext, List<OrderInfoBean.OrderListBean> itemList) {
            super(mContext, itemList);
        }

        @Override
        public void init(ZmHolder zmHolder, OrderInfoBean.OrderListBean orderListBean, int position) {
            TextView food_name = zmHolder.getView(R.id.food_name);
            TextView food_pirce = zmHolder.getView(R.id.food_pirce);
            TextView food_state = zmHolder.getView(R.id.food_state);
            TextView food_gift = zmHolder.getView(R.id.food_gift);

            food_name.getPaint().setFakeBoldText(true);

            food_name.setText(orderListBean.title);
            food_pirce.setText("¥:" + orderListBean.price + "  x" + orderListBean.nums);

            food_state.setText("2020-02-02 02:02:02");

            food_name.setTextColor(context.getResources().getColor(R.color.colorBlack));
            food_pirce.setTextColor(context.getResources().getColor(R.color.colorBlack));
            food_state.setTextColor(context.getResources().getColor(R.color.colorBlack));

            food_gift.setVisibility(orderListBean.status == 7 ? View.VISIBLE : View.GONE);
        }

        @Override
        public int setLayout() {
            return R.layout.item_dialog_sending_order;
        }
    }


    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_sending_dis:
                break;
        }
        dismissDialog();
    }
}
